package factories;

import java.awt.Graphics;
import java.awt.Point;

import javax.swing.JPanel;

import statics.Constants;

public class MapRenderer extends JPanel{

	private ETile[][] map;
	private Point start;
	
	public MapRenderer(){
		start = new Point(0,0);
	}
	
	protected void paintComponent(Graphics g){
		super.paintComponent(g);
		if(map != null){
			//Draw map
			for(int x = start.x; x < 25+start.x; x++){
				for(int y = start.y; y < 20+start.y; y++){
					ETile t = map[x][y];
					g.drawImage(t.getTile().bt.getTexture().getImage(),
							Constants.tile_dim*(x-start.x), Constants.tile_dim*(y-start.y), this);
				}
			}	
		}
	}
	
	public void setMap(ETile[][] map){
		this.map = map;
		repaint();
	}

	public void shiftTop() {
		if(start.y > 0)
			start.y--;
		repaint();
	}

	public void shiftBottom() {
		if(start.y+20 < map[0].length)
			start.y++;
		repaint();
	}

	public void shiftRight() {
		if(start.x+25 < map.length)
			start.x++;
		repaint();
	}

	public void shiftLeft() {
		if(start.x > 0)
			start.x--;
		repaint();
	}
	
}
